package com.lxn.web.controller;


import com.lxn.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class PayController {
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/pay/user/{id}")
    @HystrixCommand(fallbackMethod = "payFallback")
    public User pay(@PathVariable("id")Long id){
        //远程调用user-server
        //java代码发送http请求
        //String url = "http://localhost:1000/user/"+id;
        String url = "http://user-server/user/"+id;
        return restTemplate.getForObject(url,User.class);
    }
    public User payFallback(@PathVariable("id")Long id){
        return new User(-1L,"ribbon:用户服务不可用！");
    }
}
